#!/usr/bin/python

import sys

feat_count = {}
for line in sys.stdin:
	feature, dat = line.split('\t')
	count, label = dat.split()
	try:
		feat_count[feature]
		try:
			feat_count[feature][int(label)] += int(count)
		except KeyError:
			feat_count[feature][int(label)] = int(count)
	except KeyError:
		feat_count[feature] = {int(label):int(count), 1-int(label):0}
	
for feature in feat_count:
	print feature + "\t" + str(feat_count[feature][0]) + " " + str(feat_count[feature][1])
